package com.hnas.core.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class DTOPagedList<T> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5222118652356189043L;
	private List<T> list = new ArrayList<T>();
	private int pageNo;
	private int pageSize;
	private int totalCount;

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public String getPageStr() { // 分页代码，可转到PageTool中，或vm的宏定义中
		if (this.getTotalCount() < 0)
			return "";
		int pageCount = this.getTotalCount() / this.pageSize;
		if (pageCount * this.pageSize < this.getTotalCount())
			pageCount++;

		StringBuffer str = new StringBuffer("");
		int next, prev;
		prev = this.getPageNo() - 1;
		next = this.getPageNo() + 1;

//		if (this.getPageNo() > 1) {
//			str.append("<a href=\"#\" onclick=\"gotoPage(1);return false;\">首页</a> ");
//		} else {
//			// str.append("<a href=\"#\">首页</a> ");
//		}
//		str.append("<ul class=\"ul-yema\">");
	
//		str.append("</ul>");
//		if (pageCount > 1 && this.getPageNo() != pageCount) {
//			str.append("<a href=\"#\"  onclick='gotoPage(" + pageCount
//					+ ");return false;'>末页</a>  ");
//		} else {
//			// str.append("<a href=\"#\" >末页</a>  ");
//		}
				
		str.append(" 共" + this.getTotalCount() + "条  ");
		/*str.append("  每页" + String.valueOf(this.getPageSize()));// 页大小的设置放到查询的条件中。

		str.append("条 分" + pageCount + "页显示 转到");
		str.append("<SELECT size=1 name=Pagelist onchange='gotoPage(this.value);'>");
		for (int i = 1; i < pageCount + 1; i++) {
			if (i == this.getPageNo()) {
				str.append("<OPTION value=" + i + " selected>" + i);
//						+ "</OPTION>");
			} else {
				str.append("<OPTION value=" + i + ">" + i );//+ "</OPTION>"
			}
		}
		str.append("</SELECT>页");*/
		
		if (this.getPageNo() > 1) {
			/*str.append("<li><a href=\"#\" onclick='gotoPage(" + prev
					+ ");return false;' class=\"a-t\">上页</a></li> ");*/
			str.append("<a class=\"m_r_5\" href=\"#\" onclick='gotoPage(" + prev+ ");return false;' class=\"a-t\">上一页</a>");
		} else {
			str.append("<a href=\"#\">上一页</a> ");
		}
		str.append(this.getPageNo()+"/"+pageCount);
		if (this.getPageNo() < pageCount) {
			/*str.append("<li><a href=\"#\" onclick='gotoPage(" + next
					+ ");return false;' class=\"a-t\">下页</a></li> ");*/
			str.append("<a class=\"m_l_5 m_r_5\" href=\"#\" onclick='gotoPage(" + next
					+ ");return false;' class=\"a-t\">下一页</a>");
			
		} else {
			str.append("<a href=\"#\" >下一页</a> ");
		}
		str.append("跳转到第 <input style=\"width:30px;\" class=\"input_style2\" type=\"tel\" name=\"num\" id=\"jumpNum\"  value="+this.getPageNo()+"> 页 ");
		//str.append(",每页 <input style=\"width:30px;\" class=\"input_style2\" type=\"tel\" name=\"pageSize\" id=\"id_page_size\" value="+this.getPageSize()+"> 条 ");
		str.append("<input class=\"btn_brown02 m_r_12\" type=\"button\" name=\"button\" id=\"button\" value=\"确定\" onclick='gotoJumpPage();' class=\"a-t\">");
//		str.append("<INPUT type=hidden  value=" + this.getPageNo()
//				+ " name=\"pages\" > ");
//		str.append("<INPUT type=hidden  value=" + this.getPageSize()
//				+ " name=\"pageSize\"> ");
		return str.toString();
	}
	
	public int getLastPage(){
		int pageCount = this.getTotalCount() / this.pageSize;
		if (pageCount * this.pageSize < this.getTotalCount())
			pageCount++;
		return pageCount;
	}
}
